home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 762 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.1 KB

  1. Path: chronicle.mti.sgi.com!austern
  2. From: bill@gibbons.org (Bill Gibbons)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Static const data member initializers
  5. Date: 18 Mar 1996 09:51:23 PST
  6. Organization: -none-
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <199603181725.JAA08503@shellx.best.com>
  9. References: <0099F84782C14100.3D6072A5@ittpub.nl>
  10. NNTP-Posting-Host: isolde.mti.sgi.com
  11. X-Original-Date: Mon, 18 Mar 1996 09:26:51 -0800
  12. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  13.     iQBVAwUBMU2ip0y4NqrwXLNJAQExmAIAo0FMPLMjVGGH5kp0eEMxc6SCCe9yWhac
  14.     BNmjhIOR/Smi8AMH+Q6F6ZEARlcYHwzeUgQRnah5i1fC42qptB7kcQ==
  15.     =TXIH
  16. Originator: austern@isolde.mti.sgi.com
  17.  
  18. In article <0099F84782C14100.3D6072A5@ittpub.nl>, "Wil Evers"
  19. <wil@ittpub.nl> wrote:
  20.  
  21. > Does anyone know the rationale behind requiring a definition of a static
  22. > const data member that has been declared with an initializer? I mean, if I
  23. > write:
  24. >         // header file
  25. >         class X { static const int bufSize = 42; };
  26. > then why should I be required to write
  27. >         // some translation unit
  28. >         const int X::bufSize;
  29. > It seems to me that interpreting bufSize's declaration-with-initializer in
  30. > the class definition as a definition in class scope with internal linkage
  31. > (analogous to an inline member function) would make more sense.
  32.  
  33. But inline member functions have *external* linkage.  To make the ODR
  34. (One Definition Rule) as useful as possible, it is necessary to enforce it
  35. on all class members.
  36.  
  37. So the "make a copy in each file as needed" approach commonly used for
  38. inline non-member functions will not work here - it would break the ODR.
  39. And while there are ways to ensure that only one copy is actually used,
  40. it was felt that requiring somewhat complex implementation tricks for
  41. such a simple feature was inappropriate.
  42.  
  43. -- 
  44. Bill Gibbons
  45. bill@gibbons.org
  46. ---
  47. [ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
  48.                 newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  49.   comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  50.   Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  51.   Comments? mailto:std-c++-request@ncar.ucar.edu 
  52. ]
  53.